<?php
namespace PartnerAdmin\Controller;
use Org\Util\Rbac;
use Think\Controller;
use Think\Verify;
class AdminController extends Controller {
    public function verifyImg(){
        
        $cfg = array(
            'imageH'    =>  40,
            'imagew'    =>  54,
            'fontSize'  =>  24,
            'length'    =>  4,
            'fontttf'   =>  '1.ttf',
        );
        ob_clean();
        $very = new Verify($cfg);
        $very->entry();
    }
    public function login(){
        if(IS_AJAX){
            $account = I('u_name');
            $password = I('password');
            $captcha = I('captcha');

            $vry = new Verify();
            if($vry->check($captcha)){
                $user = D('partners');
                $info = $user->where(array('account'=>$account))->find();
                if($info){
                    if($info['password']==$password){
                        // setcookie('u_id',$info['u_id']);
                        // setcookie('u_name',$name);
                        // setcookie('r_id',$info['zhiwei']);
                        // session('u_id',$_COOKIE['u_id']);
                        // session('u_name',$_COOKIE['u_name']);
                        // session('r_id',$_COOKIE['r_id']);
                        session('nickname',$info['nickname']);
                        session('account',$info['account']);
                        session('id',$info['id']);
                        // session('auth_id',$info['auth']);
                        $data['code'] = '1';
                        $data['msg'] = '成功';
                        
                    }else{
                        $data['code'] = '-1';
                        $data['msg'] = '密码错误';
                    }
                }else{
                    $data['code'] = '-2';
                    $data['msg'] = '用户不存在';
                }
            }else{
                $data['code'] = '-3';
                $data['msg'] = '验证码错误';
            }
            echo json_encode($data);
            
        }else{

            $this->display(); 
        }  
    }
    public function index(){ 
        $account = session('account');
        if(!$account){
            $this->error('当前用户未登录或登录超时，请重新登录',U('PartnerAdmin/Admin/login'));
        }
        
        $this->display();
    }
    public function logout(){
        session(null);
        $this->redirect('Admin/login');
    }
}